package mta_scenarios;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;

/**
 * Magento Translation Assistant
 * Copyright (c) 2009 Dmitry Nikolaev
 * Contact author: blackliteon@gmail.com
 */
public class ScenarioUtil {
    private final String tmpPath = "test/tmp/";

    public void clearTmp() throws IOException {
        File tmpFile = new File(tmpPath);
        FileUtils.cleanDirectory(tmpFile);

        if (!tmpFile.exists() && !tmpFile.mkdir()) {
            System.out.println("Cant create " + tmpFile);
        }
    }

    public void createTmpDir(String s) {
        File dir = new File(getTmpDir(s));
        if (!dir.mkdir()) {
            System.out.println("Cant create " + dir);
        }
    }

    public String getTmpDir(String s) {
        return tmpPath + s + File.separator;
    }

    public String getTmpFile(String s) {
        return tmpPath + s;
    }


    public void copyDirToTmp(String src, String dest) throws IOException {
        FileUtils.copyDirectory(new File(src), new File(dest), new FileFilter() {
            public boolean accept(File file) {
                return !file.getName().startsWith(".");
            }
        });
    }

    public String getDir(String s) {
        return s + File.separator;
    }
}
